package com.atguigu.spzx.manner.service.impl;

import com.atguigu.spzx.manner.mapper.SysRoleMapper;
import com.atguigu.spzx.manner.mapper.SysUserRoleMapper;
import com.atguigu.spzx.manner.service.SysRoleUserService;
import com.atguigu.spzx.model.dto.AssginRoleDto;
import com.atguigu.spzx.model.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import spzx.util.AtguiguAssert;

import java.util.List;

@Service
public class SysRoleUserServiceImpl implements SysRoleUserService {
    @Autowired
    SysUserRoleMapper sysUserRoleMapper;
    @Transactional
    @Override
    public void doAssign(AssginRoleDto assginRoleDto) {
        Long userId = assginRoleDto.getUserId();
        sysUserRoleMapper.deleteByUserId(userId);
        List<Long> roleIdList = assginRoleDto.getRoleIdList();
        AtguiguAssert.notNull(roleIdList,"角色不能为空");
        sysUserRoleMapper.insertByUserId(assginRoleDto);
    }
}
